﻿namespace Sidvall.AuthorizationManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class ServerConnection : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.AuthorizationManager.Data.IServerConnection
    {
        #region Public Members

        #region ConnectionString

        private string _ConnectionString;
        partial void OnBeforeConnectionStringPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterConnectionStringPropertyChanged();
        public string ConnectionString
        { 
            get
            {
                return _ConnectionString;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ConnectionString = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _ConnectionString);
                    OnBeforeConnectionStringPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ConnectionString", eventData.Value, true, true);
                        OnAfterConnectionStringPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ConnectionTypeId

        private global::Sidvall.AuthorizationManager.Data.ConnectionType _ConnectionTypeId;
        partial void OnBeforeConnectionTypeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.ConnectionType> eventData);
        partial void OnAfterConnectionTypeIdPropertyChanged();
        public global::Sidvall.AuthorizationManager.Data.ConnectionType ConnectionTypeId
        { 
            get
            {
                return _ConnectionTypeId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ConnectionTypeId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.ConnectionType> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.ConnectionType>(value, _ConnectionTypeId);
                    OnBeforeConnectionTypeIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ConnectionTypeId", eventData.Value, true, true);
                        OnAfterConnectionTypeIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region IsEnabled

        private bool _IsEnabled;
        partial void OnBeforeIsEnabledPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsEnabledPropertyChanged();
        public bool IsEnabled
        { 
            get
            {
                return _IsEnabled;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _IsEnabled = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsEnabled);
                    OnBeforeIsEnabledPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("IsEnabled", eventData.Value, true, true);
                        OnAfterIsEnabledPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region IsLoaded

        private bool _IsLoaded;
        partial void OnBeforeIsLoadedPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsLoadedPropertyChanged();
        public bool IsLoaded
        { 
            get
            {
                return _IsLoaded;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _IsLoaded = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsLoaded);
                    OnBeforeIsLoadedPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("IsLoaded", eventData.Value, true, true);
                        OnAfterIsLoadedPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region Name

        private string _Name;
        partial void OnBeforeNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterNamePropertyChanged();
        public string Name
        { 
            get
            {
                return _Name;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Name = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Name);
                    OnBeforeNamePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Name", eventData.Value, true, true);
                        OnAfterNamePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region RemoteAddress

        private string _RemoteAddress;
        partial void OnBeforeRemoteAddressPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterRemoteAddressPropertyChanged();
        public string RemoteAddress
        { 
            get
            {
                return _RemoteAddress;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _RemoteAddress = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _RemoteAddress);
                    OnBeforeRemoteAddressPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("RemoteAddress", eventData.Value, true, true);
                        OnAfterRemoteAddressPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ServerConnectionId

        private System.Nullable<int> _ServerConnectionId;
        partial void OnBeforeServerConnectionIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterServerConnectionIdPropertyChanged();
        public System.Nullable<int> ServerConnectionId
        { 
            get
            {
                return _ServerConnectionId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ServerConnectionId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _ServerConnectionId);
                    OnBeforeServerConnectionIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ServerConnectionId", eventData.Value, true, true);
                        OnAfterServerConnectionIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region UserConfigurationId

        private int _UserConfigurationId;
        partial void OnBeforeUserConfigurationIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<int> eventData);
        partial void OnAfterUserConfigurationIdPropertyChanged();
        public int UserConfigurationId
        { 
            get
            {
                return _UserConfigurationId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _UserConfigurationId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<int> eventData = new Sidvall.Business.PropertyChangeEventData<int>(value, _UserConfigurationId);
                    OnBeforeUserConfigurationIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("UserConfigurationId", eventData.Value, true, true);
                        OnAfterUserConfigurationIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ServerConnectionManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ServerConnectionManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        public UserConfiguration UserConfiguration { get; set; }
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ServerConnectionManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public ServerConnection Copy()
        {
            return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ServerConnectionManager.Copy(this);
        }
        public ServerConnection Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ServerConnectionManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.AuthorizationManager.Data.IServerConnection item)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ServerConnectionManager.Import(this, item);
        }
        public void Import(global::Sidvall.AuthorizationManager.Data.IServerConnection item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ServerConnectionManager.Import(this, item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ServerConnectionManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ServerConnectionManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ServerConnectionManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ServerConnectionManager.Initialize(this, settings);
        }

        #endregion

        #region IServerConnection Members

        string global::Sidvall.AuthorizationManager.Data.IServerConnection.ConnectionString
        {
            get
            {
                return this._ConnectionString;
            }
            set
            {
                this._ConnectionString = value;
            }
        }
        global::Sidvall.AuthorizationManager.Data.ConnectionType global::Sidvall.AuthorizationManager.Data.IServerConnection.ConnectionTypeId
        {
            get
            {
                return this._ConnectionTypeId;
            }
            set
            {
                this._ConnectionTypeId = value;
            }
        }
        bool global::Sidvall.AuthorizationManager.Data.IServerConnection.IsEnabled
        {
            get
            {
                return this._IsEnabled;
            }
            set
            {
                this._IsEnabled = value;
            }
        }
        bool global::Sidvall.AuthorizationManager.Data.IServerConnection.IsLoaded
        {
            get
            {
                return this._IsLoaded;
            }
            set
            {
                this._IsLoaded = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IServerConnection.Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IServerConnection.RemoteAddress
        {
            get
            {
                return this._RemoteAddress;
            }
            set
            {
                this._RemoteAddress = value;
            }
        }
        System.Nullable<int> global::Sidvall.AuthorizationManager.Data.IServerConnection.ServerConnectionId
        {
            get
            {
                return this._ServerConnectionId;
            }
            set
            {
                this._ServerConnectionId = value;
            }
        }
        int global::Sidvall.AuthorizationManager.Data.IServerConnection.UserConfigurationId
        {
            get
            {
                return this._UserConfigurationId;
            }
            set
            {
                this._UserConfigurationId = value;
            }
        }
        global::Sidvall.AuthorizationManager.Data.IUserConfiguration global::Sidvall.AuthorizationManager.Data.IServerConnection.UserConfiguration
        {
            get
            {
                return this.UserConfiguration;
            }
            set
            {
                this.UserConfiguration = (UserConfiguration)value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public ServerConnection()
        {
        }
        public ServerConnection(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public ServerConnection(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ServerConnectionManager.Initialize(this);
        }

        #endregion
    }
}